<template>
  <div class="question">
    <image src="/static/qs_bg.png" class="qs_bg"></image>
    <u-line></u-line>
    <div style="padding: 32rpx;margin-top: 20px;margin-bottom: 10px">
      <div class="grid">
        <div class="grid-item flex-row" @click="toDay">
          <div class="flex-col group_5" >
            <text class="text8">每日一练</text>
            <text class="text10">每天练练，稳步提升</text>
          </div>
          <u-image src="/static/qs_1.png" width="30px" height="30px"></u-image>
        </div>
        <div class="grid-item flex-row" @click="toCourse">
          <div class="flex-col group_5">
            <text class="text8">课程练习</text>
            <text class="text10">针对训练，重点掌握</text>
          </div>
          <u-image src="/static/qs_2.png" width="30px" height="30px"></u-image>
        </div>
      </div>
    </div>
    <div class="qs-list">
      <u-section color="rgb(61, 155, 246)" title="练习记录" :right="false"></u-section>
      <div style="height: 20px"></div>
      <div class="group_item" v-for="item in questionRecord">
        <div>
          <div class="title">分数：{{ item.score }}/{{ item.total_score }}</div>
          <div class="number">完成 {{ item.num }}/{{ item.UserPractices.length }}题</div>
        </div>
        <div class="btns" @click="toDetail(item)">
          <div class="btn r_btn">{{ item.status === 1 ? '查看答题' : '继续答题'}}</div>
        </div>
      </div>
    </div>
    <u-empty v-if="questionRecord.length === 0" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      questionRecord: [
      ],
      categoryList: [],
      category: {
        label: ''
      },
      show: false,
      userInfo: null
    }
  },
  computed: {
    defaultValueIndex() {
      const findIndex = this.categoryList.findIndex(item => item.value === this.category.value)
      if (findIndex > -1) {
        return findIndex
      }
      return 0
    }
  },
  onShow() {
    this.userInfo = uni.getStorageSync('userInfo')
    if (this.userInfo) {
      this.$api.getPracticeList({
        user_id: this.userInfo.id
      }).then(res => {
        this.questionRecord = res
      })
    }
  },
  methods: {
    toDay() {
      uni.navigateTo({
        url: `/pages/question/day`
      })
    },
    toCourse() {
      uni.navigateTo({
        url: `/pages/question/course`
      })
    },
    confirmSelect(e) {
      this.category = e[0]
    },
    getCategoryList() {
      this.$api.categoryList().then(res => {
        this.categoryList = res.map(item => {
          return {
            value: item.id,
            label: item.name
          }
        })
        if (res.length > 0) {
          this.category = res[0].id
          this.getProductList()
        }
      })
    },
    toDetail(item) {
      if (item.status === 1) {
        uni.navigateTo({
          url: `/pages/question/detail/resultDetail?id=${item.id}`
        })
      } else {
        uni.navigateTo({
          url: `/pages/question/create/create?id=${item.id}`
        })
      }
    }
  }
}
</script>

<style lang="scss">
.question {
  height: 100%;
  overflow: auto;
  padding-bottom: 60rpx;
  position: relative;
  background-color: #f5f5f5;
  .group_item {
    font-size: 12px;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    padding: 16px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #ffffff;
    border-radius: 4px;
    margin-bottom: 20rpx;
     .title {
       width: 100%;
       margin-bottom: 16px;
       font-size: 14px;
       font-weight: 700;
     }
    .number {
      color: #999;
    }
    .btns {
      display: flex;
      align-items: center;
      .btn {
        padding: 4px 13px;
        border-radius: 15px;
        border: 1px solid #333;
        margin-left: 6px;
        font-size: 10px;
        background: #333;
        color: #fff;
      }
    }
  }
  .qs-list {
    padding: 20rpx;
  }
  .qs_bg {
    position: absolute;
    left: 0;
    top:0;
    width: 100%;
    height: 150px !important;
  }
  .grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-row-gap: 13px;
    grid-column-gap: 12px;
    .grid-item {
      padding: 20px 10px 19px;
      background-color: #fff;
      border-radius: 6px;
      display: flex;
      flex-direction: row;
    }
    .group_5 {
      flex: 1 1 auto;
      display: flex;
      flex-direction: column;
      .text8 {
        color: #333;
        font-size: 15px;
        line-height: 18px;
        white-space: nowrap;
      }
      .text10 {
        margin-top: 10px;
        color: #999;
        font-size: 12px;
        line-height: 14px;
        white-space: nowrap;
      }
    }
  }
  .pubuBox {
    padding: 20rpx;
    display: flex;
    align-items: center;
    position: relative;
    z-index: 1;
    background-color: #ffffff;
    .name {
      margin-right: 14rpx;
    }
  }
  .wp-relative {
    display: flex;
    flex-wrap: wrap;
    margin-top: 24rpx;
    padding: 0 12rpx;
    .product-item {
      width: calc(50% - 24rpx);
      background-color: #ffffff;
      margin: 12rpx 12rpx;
      padding-bottom: 24rpx;
      .product-name {
        width: 100%;
        font-size: 28rpx;
        line-height: 28rpx;
        color: #333333;
        margin-top: 24rpx;
      }

      .product-count {
        margin-top: 24rpx;
        font-size: 22rpx;
        font-family: 萍方-简;
        line-height: 20rpx;
        color: #999999;
      }
      .product-status {
        margin-top: 24rpx;
        font-size: 26rpx;
        font-family: 萍方-简;
        line-height: 26rpx;
        color: #fe9b1a;
      }
    }
  }
  .p-list {
    flex-grow: 1;
    padding: 0 10rpx;
    background-color: #fff;
    .p-item {
      padding: 20rpx;
      box-sizing: border-box;
      display: flex;
      border-bottom: 1px solid #f0f0f0;
      img {
        width: 80px;
        height: 80px;
      }
      .p-desc {
        flex: 1;
        padding-left: 20rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .p-title {
          font-size: 30rpx;
          color: #606266;
          margin-bottom: 10rpx;
        }
        .p-price-box {
          display: flex;
          justify-content: space-between;
          align-items: center;
          .add-num{
            padding: 0 16rpx;
          }
          .p-price {
            font-size: 30rpx;
            color: #333;
          }
          .add-icon {
            width: 40rpx;
            height: 40rpx;
            line-height: 40rpx;
            text-align: center;
            background-color: rgb(61, 155, 246);
            color: #fff;
            border-radius: 50%;
          }
        }
      }
    }
  }
  .category-content {
    display: flex;
    height: 100%;
    overflow: hidden;
  }
  .c-silde {
    background-color: #f8f8f8;
    width: 160rpx;
  }
  .c-item {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 52px;
    font-size: 14px;
    color: #606266;
    position: relative;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 50%;
      -webkit-transform: translateY(-50%);
      transform: translateY(-50%);
      height: 15px;
      width: 4px;
      opacity: .8;
      background-color: transparent;
    }
    &.active {
      color: rgb(61, 155, 246);
      background-color: #fff;
      &::before {
        background-color: rgb(61, 155, 246);
      }
    }
  }
  .top {
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    height: 125rpx;
    position: fixed;
    top: 0;
    z-index: 9;
    background-image: url("@/static/top.png");
    .top-title {
      position:absolute;
      top: 30rpx;
      width: 100%;
      text-align: center;
      font-size: 36rpx;
      color: #FFFFFF;
      font-weight: bold;
    }
  }
}
</style>
